<?php
/**
* Simple example script using PHPMailer with exceptions enabled
* @package phpmailer
* @version $Id$
*/
if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'multiple') {
error_reporting(E_ALL);

$body = $_POST['mail_body'];
$subjet = $_POST['subjet'];

include_once('../controller/includes/db_access.php');
require '../controller/PHPMailer_5.2.1/class.phpmailer.php';

$sql = mysql_query("SELECT * FROM newsletter WHERE aktief='Y' AND received='0'");
$numRows = mysql_num_rows($sql); // Added for "End Campaign Check" at the bottom of this file(not shown on the video)
while($row = mysql_fetch_array($sql)){
	$id = $row["newsletter_id"];
	$naam = $row["first_name"];
        $email = $row["email"];
        $bedrijf = $row["compagny"];
        



try {
   $mail = new PHPMailer(true); //New instance, with exceptions enabled
	
	//$body   = file_get_contents($body);
           
	$body             = preg_replace('/\\\\/','', $body); //Strip backslashes

	//$mail->IsSMTP();                           // tell the class to use SMTP
	//$mail->SMTPAuth   = true;                  // enable SMTP authentication
	//$mail->Port       = 25;                    // set the SMTP server port
	//$mail->Host       = "mail.yourdomain.com"; // SMTP server
	//$mail->Username   = "name@domain.com";     // SMTP server username
	//$mail->Password   = "password";            // SMTP server password

	//$mail->IsSendmail();  // tell the class to use Sendmail

	$mail->AddReplyTo("name@domain.com","First Last");

	$mail->From       = "info@dbme.nl";
	$mail->FromName   = "dbme.nl";

	$to = "$email";

	$mail->AddAddress($to);

	$mail->Subject  = $subjet;

	$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
	$mail->WordWrap   = 80; // set word wrap

	$mail->MsgHTML($body);

	$mail->IsHTML(true); // send as HTML

	$mail->Send();
        
        if ($mail->Send()) {
            
		mysql_query("UPDATE newsletter SET received='1' WHERE email='$email' LIMIT 1");
                
                //echo 'Message has been sent.';
                
	} else {
            
	   // this else statement can be used to write into an error log if the mail function fails
	   // It can also be removed if you do not need error logging
	}
	
} catch (phpmailerException $e) {
	echo $e->errorMessage();
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]>
<script
src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="styles/style.css" type="text/css" />
<!--[if lte IE 7]>
<link rel="stylesheet" href="style_ie.css" />
<![endif]-->
<title>dbme!!!!</title>
</head>
<body>
<div id="bloc_page">
<header>
 <a href="#"><img src="../images/dBmelogo.png" alt="referentie" alt="dbme!" /></a>
</header>  
 <nav>
    <?php include_once('header.php'); ?>
</nav>
 <section>
     
<article>
    <form style="width:440px;" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >

        <input type="hidden" name="action" value="multiple" />

        <div style="text-align:left; padding:24px; margin:15px 0px 25px 25px;"> 

            <p> Newsletter &nbsp;</p> 

            <br /><br />
            <p>Onderwerp:</p>
            <input type="text" name="subjet"  size="60" value="" /><br />

            <p>Mail Body</p>
            <textarea name="mail_body" rows="20" cols="80">

            </textarea><br /><br />

            <input name="mySubmitBtn" type="submit" value="Send" />

    <?php echo $msg_to_user; ?>

        </fieldset> 

        </div>
    </form>
   </article>
 
</section>
 
 <footer>  
<p>Lorem ipsum dolor sit amet...</p>
<p>Vivamus sed libero nec mauris pulvinar facilisis ut non sem...</p>
<p>Phasellus ligula massa, congue ac vulputate non, dignissim at augue...</p>
</footer>
</div>
</body>
</html>